package cn.cymym.dao;

import cn.cymym.domain.User;
import cn.cymym.utils.ComDao;

public class UserDaoImpl extends ComDao<User> implements UserDao {

	@Override
	public void register(User user) {
		// TODO 用户注册
		String sql = "INSERT INTO USER(usernumber,tel,pwd) VALUES(?,?,?)";
		update(sql,user.getUserNumber(), user.getTel(),user.getPwd());
	}

	@Override
	public long isExsit(String tel) {
		// TODO 该用户是否已存在
		String sql = "SELECT COUNT(id) FROM USER WHERE tel = ?";
		return getForValue(sql,tel) ;
	}

	@Override
	public User getTelAndPwd(String tel) {
		// TODO 查询用户信息
		String sql = "SELECT * FROM USER WHERE tel = ?";
		User user = null;
		try {
			 user = get(sql, tel);
			 return user;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}

	@Override
	public void updateUserInfo(User user) {
		// TODO 保存跟新用户信息
		String sql = "UPDATE USER SET NAME=?,tel=?,email=?,\r\n" + 
				"qq=?,gender=?,birthday=? WHERE usernumber = ?";
		update(sql, user.getName(),user.getTel(),user.getEmail(),user.getQq(),
				user.getGender(),user.getBirthday(),user.getUserNumber());
	}

	

}
